﻿@using WebShop.Controllers
@model IEnumerable<WebShop.Models.ShoppingModel>

@{
    ViewBag.Title = "Shopping";
}

<h2>Shopping</h2>
<div>
    <h3># of items in basket: <span id="ItemCount">@ViewData["ItemCount"]</span></h3>
    @using (Html.BeginForm("Index", "Basket"))
    {
        <p>
            <input type="submit" value="Go to basket" />
        </p>
    }
</div>
<table>
    <tr>
        <th>
            Item Id
        </th>
        <th>
            Description
        </th>
        <th>
            UnitPrice
        </th>
        <th>
            Quantity
        </th>
        <th>
        </th>
    </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Code)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.UnitPrice)
            </td>
            <td>
                @Html.EditorFor(modelItem => item.Quantity)
            </td>
            <td>
                @Ajax.ActionLink("Add to basket", "AddItem", item, 
                new AjaxOptions 
                {
                    HttpMethod = "POST", 
                    UpdateTargetId="ItemCount", 
                    InsertionMode = InsertionMode.Replace
                })
            </td>
        </tr>
    }

</table>


@section scripts{


    @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")


}

